package main

import (
	"go.uber.org/zap"
	"go.uber.org/zap/zapcore"
	"os"
)

var logger *zap.Logger
var sugarLogger *zap.SugaredLogger

func InitLogger() {
	encoder := getEncoder()
	writerSyncer := getLogWriter()
	core := zapcore.NewCore(encoder, writerSyncer, zapcore.DebugLevel)
	logger = zap.New(core, zap.AddCaller())
	sugarLogger = logger.Sugar()
}

func getEncoder() zapcore.Encoder {
	encoderConfig := zap.NewProductionEncoderConfig()
	encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
	encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
	return zapcore.NewConsoleEncoder(encoderConfig)
	//return zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig())
}

func getLogWriter() zapcore.WriteSyncer {
	return os.Stdout
	
	//file, _ := os.Create("./f_zap_develop/zap_analysis/test.log")
	//return file

	//lumberJackLogger := &lumberjack.Logger{
	//	Filename:   "./f_zap_develop/zap_analysis/test.log",
	//	MaxSize:    10,
	//	MaxBackups: 5,
	//	MaxAge:     30,
	//	Compress:   false,
	//}
	//return zapcore.AddSync(lumberJackLogger)

}

func main() {
	InitLogger()
	defer logger.Sync()
	logger.Info("测试日志语句。。。", zap.String("键值对形式, 我的键", "键值对形式, 我的值"), zap.String("name", "我不叫张三！！"))

}
